package portal.pubimpl.system.pf;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import portal.pub.util.pf.ResultUtil;

import portal.pub.util.pf.JsonObjectUtil;
import portal.pub.util.pf.Result;
import portal.pubitf.system.INoticeMapper;
import portal.pubitf.system.pf.INoticeService;
import portal.pubvo.system.NoticeVo;

@Service("noticeServiceImpl")
public class NoticeServiceImpl implements INoticeService {

	@Autowired
	private INoticeMapper noticeMapper;


	@Override
	public Result getAll() {
		Result result = new Result();
		Map<String,Object> noticeList = new HashMap<String,Object>();
		noticeList.put("code", 0);
		noticeList.put("msg", "");
		noticeList.put("count", this.getTotal());
		noticeList.put("data", noticeMapper.getAll());
		result.setJson(JsonObjectUtil.objectTojson(noticeList));
		return result;
	}
	

	@Override
	public ResultUtil getPageAll(Integer page, Integer limit,String title) {
		PageHelper.startPage(page, limit);
		List<NoticeVo> list = noticeMapper.getPageAll(title);
		PageInfo<NoticeVo> listInfo = new PageInfo<>(list);
		ResultUtil resultUtil = new ResultUtil();
		resultUtil.setCode(0);
		resultUtil.setCount(listInfo.getTotal());
		resultUtil.setData(listInfo.getList());
		return resultUtil;
	}


	@Override
	public Integer getTotal() {
		return noticeMapper.getTotal();
	}


	@Override
	public Integer addNotice(NoticeVo vo) {
		return noticeMapper.insert(vo);
	}


	@Override
	public Integer editNotice(NoticeVo vo) {
		return noticeMapper.update(vo);
	}


	@Override
	public Integer deleteNotice(String id) {
		return noticeMapper.delete(id);
	}


	@Override
	public Integer deleteNoticeInId(String[] delList) {
		return noticeMapper.deleteInId(delList);
	}
	
	
}
